|
|
|
|
|
|
|
Figure P6-1:
The main form of the Icon View application |
|
|
|
|
|
|
|
|
Figure P6-1 shows the main form of the IconView application as it should appear. Each option button selects a different predefined icon. |
|
|
|
|
|
|
|
|
The m_IconID variable in the IconView project (on the CD that comes with this book) holds the constant value corresponding to the selected icon. During the picture box Paint event, the LoadIcon function is used to load the actual icon resource. The DrawIcon function is used to draw the icon onto the picture box. The DrawIcon function is described in the Win32 documentation as follows: |
|
|
|
|
|
|
|
|
BOOL DrawIcon( HDC hdc, // handle to device context
int X, // x-coordinate of upper-left corner
int Y, // y-coordinate of upper-left corner
HICON hIcon // handle to icon to draw
); |
|
|
|
|
|
|
|
|
The hDC parameter is the device context of the window on which you are drawing, the X and Y parameters specify the location for the icon, and the hIcon parameter is the handle to the iconall 32 bits, all by value. |
|
|
|
|
|
|
|
|
Here's the sample program: |
|
|
|
|
|
|
|
|
' IconView Puzzle
' Copyright © 1998 by Desaware Inc. All Rights Reserved
Option Explicit
Private Declare Function LoadIcon Lib "user32.dll" Alias _
"LoadIconA" ( _
ByVal hInstance As Long, _
ByVal lpIconName As String) As Long
Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, _
ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Const IDI_APPLICATION = 32512& |
|
|
|
|
|